import 'package:flutter/material.dart';
class DismissibleTest extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return Scaffold(appBar: AppBar(title: Text('Dismissible 示例'),),
    body: DismissibleEx(),);
  }
}
class DismissibleEx extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return _DismissibleEx();
  }
}

class _DismissibleEx extends State<DismissibleEx>{
  List<int> items = List<int>.generate(100, (index) => index);
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: items.length,
        padding: const EdgeInsets.symmetric(vertical: 16),
        itemBuilder: (BuildContext context, int index){
          return Dismissible(
            key: ValueKey<int>(items[index]),
            child: ListTile(
              title: Text('Item ${items[index]}'),
            ),
            background: Container(color: Colors.green,
              alignment: Alignment.centerLeft,
              child: Icon(Icons.check),),
            onDismissed: (DismissDirection direction){
              setState(() {
                items.removeAt(index);
              });
            },
            secondaryBackground: Container(
              alignment: Alignment.centerRight,
              child: Icon(Icons.cancel),
              color: Colors.blue,),
          );
        }
    );
  }
}